package com.lee.controller.goods;


import com.alibaba.dubbo.config.annotation.Reference;
import com.lee.aspect.Log;
import com.lee.base.Result;
import com.lee.goods.api.IMallBrandService;
import com.lee.goods.entity.MallBrand;
import com.lee.page.TableSupport;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lee.constant.BusinessType;
import com.lee.base.BaseController;

/**
 * 品牌 信息操作处理
 * 
 * @author LiPengFei
 * @date 2018-10-05
 */
@Controller
@RequestMapping("/goods/mallBrand")
public class MallBrandController extends BaseController
{
    private String prefix = "goods/mallBrand";
	
	@Reference
	private IMallBrandService mallBrandService;
	
	@RequiresPermissions("goods:mallBrand:view")
	@GetMapping()
	public String mallBrand()
	{
	    return prefix + "/mallBrand";
	}
	
	/**
	 * 查询品牌列表
	 */
	@RequiresPermissions("goods:mallBrand:list")
	@PostMapping("/list")
	@ResponseBody
	public Result list(MallBrand mallBrand)
	{
		return  Result.ok().page(mallBrandService.selectMallBrandList(mallBrand, TableSupport.getPageDomain()));
	}
	
	/**
	 * 新增品牌
	 */
	@RequiresPermissions("goods:mallBrand:add")
	@Log(title = "品牌", action = BusinessType.INSERT)
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}

	/**
	 * 修改品牌
	 */
	@RequiresPermissions("goods:mallBrand:edit")
	@Log(title = "品牌", action = BusinessType.UPDATE)
	@GetMapping("/edit/{brandId}")
	public String edit(@PathVariable("brandId") Long brandId, Model model)
	{
		MallBrand mallBrand = mallBrandService.selectMallBrandById(brandId);
		model.addAttribute("mallBrand", mallBrand);
	    return prefix + "/edit";
	}
	
	/**
	 * 保存品牌
	 */
	@RequiresPermissions("goods:mallBrand:save")
	@Log(title = "品牌", action = BusinessType.SAVE)
	@PostMapping("/save")
	@ResponseBody
	public Result save(MallBrand mallBrand)
	{
		if (mallBrandService.saveMallBrand(mallBrand) > 0)
		{
			return Result.ok();
		}
		return Result.error();
	}
	
	/**
	 * 删除品牌
	 */
	@RequiresPermissions("goods:mallBrand:remove")
	@Log(title = "品牌", action = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public Result remove(String ids)
	{
		int rows = mallBrandService.deleteMallBrandByIds(ids);
		if (rows > 0)
        {
            return Result.ok();
        }
        return Result.error();
	}
	
}
